﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace SportManager
{
    /// <summary>
    /// Class for keeping Exercises data in file
    /// </summary>
    public class ExerciseFileKeeper : IDataManager<List<ExerciseInfo>>, IListOfIdOwners<ExerciseInfo>
    {
        /// <summary>
        /// Get Exercises list (operation may be long if it run for the first time)
        /// </summary>
        /// <returns>List of ExerciseInfo's</returns>

        public ExerciseFileKeeper()
        {
#if DEBUG
            ExerciseFilePath = Settings.Default.ExercisesFileName;
#else
            ExerciseFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + '\\' + Settings.Default.EnglishProgramName + '\\' + Settings.Default.ExercisesFileName;
#endif
        }

        public List<ExerciseInfo> GetData()
        {
            return KeepersBridge<FileKeeper<List<ExerciseInfo>>, List<ExerciseInfo>>.GetData(new string[] { ExerciseFilePath });
        }

        /// <summary>
        /// Save Exercises list
        /// </summary>
        public void SaveData()
        {
            KeepersBridge<FileKeeper<List<ExerciseInfo>>, List<ExerciseInfo>>.SaveData(new string[] { ExerciseFilePath });
        }

        /// <summary>
        /// Get index of searched exercise in list of data
        /// </summary>
        /// <param name="guid">Searched guid</param>
        /// <returns>Index of searched item</returns>
        public int GetItemIndex(Guid guid)
        {
            return ListItemsFinder.GetItemIndex(GetData(), guid);
        }

        /// <summary>
        /// Find exercise by guid
        /// </summary>
        /// <param name="guid">Guid of exercise</param>
        /// <returns>Founded exercise or exeption if it's not found</returns>
        public ExerciseInfo FindItemByGuid(Guid guid)
        {
            return ListItemsFinder.FindItemByGuid(GetData(), guid);
        }

        private readonly string ExerciseFilePath;
    }

    /// <summary>
    /// Class for keeping Trainings data in file
    /// </summary>
    public class TrainingsFileKeeper : IDataManager<List<Training>>, IListOfIdOwners<Training>
    {
        /// <summary>
        /// Get Trainings list (operation may be long if it run for the first time)
        /// </summary>
        /// <returns>List of Training's</returns>

        public TrainingsFileKeeper()
        {
#if DEBUG
            TrainingsFilePath = Settings.Default.TrainingsFileName; 
#else
            TrainingsFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + '\\' + Settings.Default.EnglishProgramName + '\\' + Settings.Default.TrainingsFileName;
#endif
        }

        public List<Training> GetData()
        {
            return KeepersBridge<FileKeeper<List<Training>>, List<Training>>.GetData(new string[] { TrainingsFilePath });
        }        

        /// <summary>
        /// Save Trainings list to file
        /// </summary>
        public void SaveData()
        {
            KeepersBridge<FileKeeper<List<Training>>, List<Training>>.SaveData(new string[] { TrainingsFilePath });
        }

        /// <summary>
        /// Get index of searched training in list of data
        /// </summary>
        /// <param name="guid">Searched guid</param>
        /// <returns>Index of searched item</returns>
        public int GetItemIndex(Guid guid)
        {
            return ListItemsFinder.GetItemIndex(GetData(), guid);
        }

        /// <summary>
        /// Find training by guid
        /// </summary>
        /// <param name="guid">guid of training</param>
        /// <returns>Founded training or exeption if it's not found</returns>
        public Training FindItemByGuid(Guid guid)
        {
            return ListItemsFinder.FindItemByGuid(GetData(), guid);
        }

        private readonly string TrainingsFilePath;
    }

    /// <summary>
    /// Class for keeping Antropometrical data in file
    /// </summary>
    public class AntropometricalFileKeeper : IDataManager<List<AntropometricalData>>, IListOfIdOwners<AntropometricalData>
    {
        /// <summary>
        /// Get Antropometrical Data list (operation may be long if it run for the first time)
        /// </summary>
        /// <returns>List of AntropometricalData's</returns>

        public AntropometricalFileKeeper()
        {
#if DEBUG
            AntropometricalFilePath = Settings.Default.AntropometricalFileName;
#else
            AntropometricalFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + '\\' + Settings.Default.EnglishProgramName + '\\' + Settings.Default.AntropometricalFileName;
#endif
        }

        public List<AntropometricalData> GetData()
        {

            return KeepersBridge<FileKeeper<List<AntropometricalData>>, List<AntropometricalData>>.GetData(new string[] { AntropometricalFilePath });
        }

        /// <summary>
        /// Save AntropometricalData list to file
        /// </summary>
        public void SaveData()
        {
            KeepersBridge<FileKeeper<List<AntropometricalData>>, List<AntropometricalData>>.SaveData(new string[] { AntropometricalFilePath });
        }

        /// <summary>
        /// Get index of searched antropometrical data in list of data
        /// </summary>
        /// <param name="guid">Searched guid</param>
        /// <returns>Index of searched item</returns>
        public int GetItemIndex(Guid guid)
        {
            return ListItemsFinder.GetItemIndex(GetData(), guid);
        }

        /// <summary>
        /// Find antropometrical data by guid
        /// </summary>
        /// <param name="guid">guid of antropometrical data</param>
        /// <returns>Founded antropometrical data or exeption if it's not found</returns>
        public AntropometricalData FindItemByGuid(Guid guid)
        {
            return ListItemsFinder.FindItemByGuid(GetData(), guid);
        }

        private readonly string AntropometricalFilePath;
    }
}